package com.donfu.web.controller.house;

import java.util.Date;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.donfu.common.annotation.Log;
import com.donfu.common.core.controller.BaseController;
import com.donfu.common.core.domain.AjaxResult;
import com.donfu.common.enums.BusinessType;
import com.donfu.system.domain.house.HouseCollection;
import com.donfu.system.service.house.IHouseCollectionService;
import com.donfu.common.utils.poi.ExcelUtil;
import com.donfu.common.core.page.TableDataInfo;

/**
 * 收藏Controller
 * 
 * @author 曹雨心
 * @date 2021-12-01
 */
@RestController
@RequestMapping("/house/collection")
public class HouseCollectionController extends BaseController
{
    @Autowired
    private IHouseCollectionService houseCollectionService;

    /**
     * 查询收藏列表
     */
    @PreAuthorize("@ss.hasPermi('house:collection:list')")
    @GetMapping("/list")
    public TableDataInfo list(HouseCollection houseCollection)
    {
        startPage();
        List<HouseCollection> list = houseCollectionService.selectHouseCollectionList(houseCollection);
        return getDataTable(list);
    }

    /**
     * 根据用户id 查询收藏列表
     */
    @PreAuthorize("@ss.hasPermi('house:collection:list')")
    @GetMapping("/userList")
    public TableDataInfo userList(HouseCollection houseCollection)
    {
        startPage();
        List<HouseCollection> list = houseCollectionService.selectHouseCollectionByUser(houseCollection);
        return getDataTable(list);
    }

    /**
     * 导出收藏列表
     */
    @PreAuthorize("@ss.hasPermi('house:collection:export')")
    @Log(title = "收藏", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HouseCollection houseCollection)
    {
        List<HouseCollection> list = houseCollectionService.selectHouseCollectionList(houseCollection);
        ExcelUtil<HouseCollection> util = new ExcelUtil<HouseCollection>(HouseCollection.class);
        return util.exportExcel(list, "收藏数据");
    }

    /**
     * 获取收藏详细信息
     */
    @PreAuthorize("@ss.hasPermi('house:collection:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(houseCollectionService.selectHouseCollectionById(id));
    }

    /**
     * 新增收藏
     */
    @PreAuthorize("@ss.hasPermi('house:collection:add')")
    @Log(title = "收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseCollection houseCollection)
    {
        houseCollection.setCreateDate(new Date());
        return toAjax(houseCollectionService.insertHouseCollection(houseCollection));
    }

    /**
     * 修改收藏
     */
    @PreAuthorize("@ss.hasPermi('house:collection:edit')")
    @Log(title = "收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseCollection houseCollection)
    {
        houseCollection.setUpdateDate(new Date(
                
        ));
        return toAjax(houseCollectionService.updateHouseCollection(houseCollection));
    }

    /**
     * 删除收藏
     */
    @PreAuthorize("@ss.hasPermi('house:collection:remove')")
    @Log(title = "收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(houseCollectionService.deleteHouseCollectionByIds(ids));
    }
}
